package com.jt.demo1;

import com.jt.demo1.config.SpringConfig;
import com.jt.demo1.proxy.JDKProxy;
import com.jt.demo1.proxy.TimeProxy;
import com.jt.demo1.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestTx {
    public static void main(String[] args) {
        //启动容器
        ApplicationContext context =
                new AnnotationConfigApplicationContext(SpringConfig.class);
        //1.获取目标对象,userServiceImpl的实现类对象,接口是userService
        UserService target = context.getBean(UserService.class);
        System.out.println(target.getClass());
        //2.获取代理对象,实现了userService接口
        UserService proxy = (UserService) JDKProxy.getProxy(target);
        System.out.println(proxy.getClass());
        proxy.addUser();
        UserService timeProxy = (UserService) TimeProxy.getProxy(target);
        timeProxy.addUser();
    }
}
